//
//  YZMCaluateView.m
//  YZMicroStock
//
//  Created by apple on 2017/12/4.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMCaluateView.h"
#import "YZMCaluateViewCell.h"

static NSString *const identifier = @"YZMCaluateViewCell";

@interface YZMCaluateView ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UILabel *labelExample;

@property (weak, nonatomic) IBOutlet UILabel *labelTradeTop;

@property (weak, nonatomic) IBOutlet UILabel *labelT_1Top;

@property (weak, nonatomic) IBOutlet UILabel *labelT_1Bottom;

@property (weak, nonatomic) IBOutlet UILabel *labelT_DTop;

@property (weak, nonatomic) IBOutlet UILabel *labelT_DBottom;

@property (weak, nonatomic) IBOutlet UILabel *labelDiscountTop;

@property (weak, nonatomic) IBOutlet UILabel *labelDiscountBottom;


@property (weak, nonatomic) IBOutlet UILabel *labelTradeBottom;

@property (weak, nonatomic) IBOutlet UIView *viewAlpha;

@property (weak, nonatomic) IBOutlet UIView *viewContent;

@property (weak, nonatomic) IBOutlet UITableView *myTableView;

@property (weak, nonatomic) IBOutlet UIView *viewBottom;

@property (weak, nonatomic) IBOutlet UIButton *btnGain;

@end

@implementation YZMCaluateView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)awakeFromNib{
    [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];
    self.viewContent.alpha = 0;
    self.viewAlpha.backgroundColor = [UIColor blackColor];
    self.viewAlpha.alpha = 0;
    [self.btnGain setTitleColor:[YZMAppStyle colorForRiseText] forState:UIControlStateNormal];
    _myTableView.dataSource = self;
    _myTableView.delegate = self;
    [_myTableView registerNib:[UINib nibWithNibName:NSStringFromClass([YZMCaluateViewCell class]) bundle:nil] forCellReuseIdentifier:identifier];
    _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [YZMAppStyle addTopLineViewWithParentView:self.viewBottom color:[YZMAppStyle colorForLine]];
    [YZMSetBorderAndCornerRadius setView:self.viewContent borderWidth:0 borderColor:nil cornerRadius:4.0];
    self.labelExample.textColor  = [YZMAppStyle colorForGrayText];
    self.labelTradeTop.textColor = [YZMAppStyle colorForGrayText];
    self.labelTradeBottom.textColor = [YZMAppStyle colorForGrayText];
    self.labelT_1Top.textColor = [YZMAppStyle colorForGrayText];
    self.labelT_1Bottom.textColor = [YZMAppStyle colorForGrayText];
    self.labelT_DTop.textColor = [YZMAppStyle colorForGrayText];
    self.labelT_DBottom.textColor = [YZMAppStyle colorForGrayText];
    self.labelDiscountTop.textColor = [YZMAppStyle colorForGrayText];
    self.labelDiscountBottom.textColor = [YZMAppStyle colorForGrayText];
    if (ScreenWidth == 320) {
        self.constraintViewContentLeading.constant = 0;
        self.constraintViewContentTrailing.constant = 0;
    }
}


- (IBAction)clickedCloseBtn:(id)sender {
    [self hiddenSelf];
    if (self.hiddenHandle) {
        self.hiddenHandle();
    }
}

- (IBAction)clickedBtn:(id)sender {
    [self hiddenSelf];
    if (self.handle) {
        self.handle();
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YZMCaluateViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    NSDictionary *dic = self.arrData[indexPath.row];
    cell.dic = dic;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (void)show{
    if (self.superview) {
        self.hidden = NO;
        [UIView animateWithDuration:0.25 animations:^{
            self.viewContent.alpha = 1;
            self.viewAlpha.alpha = 0.5;
        }];
        return;
    }
    UIWindow *wd = [[UIApplication sharedApplication].delegate window];
    [wd addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(wd);
    }];
    [UIView animateWithDuration:0.25 animations:^{
        self.viewContent.alpha = 1;
        self.viewAlpha.alpha = 0.5;
    }];
}

- (void)hiddenSelf{
    [UIView animateWithDuration:0.25 animations:^{
        self.viewContent.alpha = 0;
        self.viewAlpha.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}


@end
